/*
* @Author: Turbidsoul
* @Date:   2015-05-12 17:47:46
* @Last Modified 2015-06-14
* @Last Modified time: 2015-08-26 23:00:16
*/

'use strict';

var app = angular.module('crawlerapp.controllers', ['crawlerapp.filters', 'crawlerapp.services']);

app.controller('WebSitesCtrl', ['$scope', '$http', function ($scope, $http) {
    $http.get('/websites').success(function(data){
        $scope.websites = data;
    });
}]);

app.controller('WebSiteCtrl', ['$scope', '$routeParams', '$http', function($scope, $routeParams, $http){
    $scope.type = $routeParams.type;
    $scope.items = {
    };
    if($routeParams.type != 'tieba') {
        $http.get('/website/' + $routeParams.type).success(function(data){
            $scope.items = data['items'];
        });
    }
    $scope.load_data = function(keyword, page) {
        if(keyword) {
            $http.get('/website/' + $routeParams.type + "/" + keyword + '/' + page).success(function(data){
                $scope.items = data['items'];
                $scope.page = data['page'];
                $scope.last = data['last'];
            });
        } else {
            $http.get('/website/' + $routeParams.type + "/" + page).success(function(data){
                $scope.items = data['items'];
                $scope.page = data['page'];
            });
        }
    };
}]);
